<?php
//設定ファイル
require_once 'config/path.php';
//ベースコントローラ
require_once 'controller/base_controller.php';
//ベースモデル
require_once 'model/base_model.php';
//appコントローラ
require_once APP_ROOT_PATH . DS . 'app_controller.php';
//appコントローラ
require_once APP_ROOT_PATH . DS . 'app_model.php';
/**
 * Bootstrap 
 * 
 * @package 
 * @version $id$
 * @author kamisiro.memo <kamisiro.memo@gmail.com> 
 */
class Bootstrap
{
    /**
     * [__construct] 
     * 
     * @access public
     * @return void
     */
    public function __construct()
    {
    }

    /**
     * [run] 
     * 
     * @param mixed $controller_name 
     * @static
     * @access public
     * @return void
     */
    public static function run($controller_name = null)
    {
        $c_obj = self::getController($controller_name);
        
        if ($c_obj) {
            
            $c_obj->setViewName($controller_name);
            $c_obj->preExecute();
            $c_obj->execute();
            $c_obj->afterExecute();
            $c_obj->render();
        
        }
    }

    /**
     * [getController] 
     * 
     * @param mixed $controller_name 
     * @static
     * @access public
     * @return void
     */
    public static function getController($controller_name = null)
    {
        if ($controller_name === null) {
            trigger_error('Not Such Controller : ' . $controller_name);
            return false; 
        }
        
        $file_path = CONTROLLER_ROOT_PATH . $controller_name . '.php'; 

        if (file_exists($file_path) === false) {
            trigger_error('Not Such Controller : ' . $controller_name . '.php');
            return false; 
        }

        $req = array_merge($_POST, $_GET);
        require_once ($file_path);
        $classname = $controller_name . 'Controller';
        $controller = new  $classname($req);

        return $controller;
    }
}
